package test.day02;

import java.util.Arrays;

public class Arraytest2 {

    public static void main(String[] args) {
        int[] arr = new int[10];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 100);
        }
        System.out.println(Arrays.toString(arr));


        //从最大值开始排序
        for (int j = arr.length - 1; j > 0; j--) {
            for (int i = j - 1; i >= 0; i--) {
                if (arr[i] > arr[j]) {
                    int temp = arr[j];
                    arr[j] = arr[i];
                    arr[i] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));

        //假排序，真冒泡
//        for(int j = 0; j < arr.length; j++){
//            for(int i = arr.length - 1; i > 0; i--){
//                if (arr[i] < arr[i-1]) {
//                    int temp = arr[i];
//                    arr[i] = arr[i-1];
//                    arr[i-1] = temp;
//                }
//            }
//        }
//        System.out.println(Arrays.toString(arr));


        //从最小值开始排序
        for (int j = 0; j < arr.length - 1; j++) {
            for (int i = 1 + j; i < arr.length; i++) {
                if (arr[i] < arr[j]) {
                    int temp = arr[j];
                    arr[j] = arr[i];
                    arr[i] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(arr));


    }


}
